﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Web.Mvc;
using ShopB2C.Entity;
using ShopB2C.ViewModels;
using Valor.Helper;
using Valor.Helpr.Enums;

namespace xTeam.HengLe.Controller.Manage
{
    public class OrderController : BaseController
    {
        /// <summary>
        /// 销售单
        /// </summary>
        public ActionResult SaleList([DefaultValue(0)]int number)
        {
            int pageCount = 0;
            List<OrderEntity> orderList = _orderAccess.SaleList(-1 , number , ref pageCount);
            ViewData["Pager"] = this.CreatePager(Url.Action("SaleList" , new { number = "{0}" }) , pageCount , number);
            return View(orderList);

        }

        public ActionResult WaitProcessOrders([DefaultValue("")]string orderId, [DefaultValue((int)Enums.OrderState.All)]int orderState, [DefaultValue(0)]int number)
        {
            int pageCount = 0;
            List<OrderEntity> orderList = _orderAccess.SaleList(-1, number, ref pageCount, (Enums.OrderState)orderState,orderId);
            ViewData["Pager"] = this.CreatePager(Url.Action("SaleList", new { number = "{0}" }), pageCount, number);
            return View(orderList);
        }

        public ActionResult SaleHistory()
        {
            return RedirectToAction("SaleList");
        }

        /// <summary>
        /// 订单预览
        /// </summary>
        public ActionResult SaleView(
            [DefaultValue("")]string orderId
            , [DefaultValue(0)]int uid)
        {
            OrderViewModel orderView = _orderAccess.SaleOrderView(uid , orderId);
            if (orderView == null)
            {
                MessageHelper msg = new MessageHelper("order");
                msg.DefaultOperate(string.Format("javascript:{0}" , JavaScriptHelper.Alert(null , AlertType.ClosePage , null)));
                msg.AddBody(1);
                msg.AddMessage(1);
                return this.MessageResult(msg.CreateMessage());
            }
            return View(orderView);
        }
        /// <summary>
        /// 删除订单
        /// </summary>
        public ActionResult SaleItemDelete(string orderId = "" , int uid = 0)
        {
            MessageHelper msg = new MessageHelper("order");
            msg.DefaultOperate("javascript:window.CloseDialog()");
            int result = _orderAccess.SaleDeleteItem(orderId , uid);
            msg.AddBody(result);
            msg.AddMessage(result);
            return this.MessageResult(msg.CreateMessage() , ResultType.AjaxHtml);
        }
        /// <summary>
        /// 订单处理
        /// </summary>
        public ActionResult SaleProcess(
            int state = 0
            , int uid = 0
            , string orderId = ""
            , string expressNo = ""
            , string description = ""
            )
        {
            _orderAccess.SalesProcess(state , expressNo , description , orderId,uid);
            return new EmptyResult();
        }
    }
}
